package com.jyy.prefabricated.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jyy.prefabricated.common.AjaxResult;
import com.jyy.prefabricated.dto.*;
import com.jyy.prefabricated.entity.SysTeam;
import com.jyy.prefabricated.entity.SysUser;
import com.jyy.prefabricated.service.SysTeamService;
import com.jyy.prefabricated.service.SysUserService;
import com.jyy.prefabricated.utils.UserUtils;
import com.jyy.prefabricated.vo.StudentsOfficialVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 运营商
 *
 * @version 1.0.0
 * @author: zjj
 */
@Slf4j
@RequestMapping("/api")
@RestController
public class SysTeamController {

    @Autowired
    private SysTeamService teamService;

    @Autowired
    private UserUtils userUtils;


    /**
     * 修改用户
     *
     * @param dto
     * @return
     */
    @PutMapping("/team")
    public AjaxResult update(@Valid @RequestBody SysTeam dto) {
        log.info("Rest request to update user:{}", dto);
        SysUser user = userUtils.getCurrentUser();
        dto.setTeamCode(user.getTeamCode());
        teamService.update(dto);
        return AjaxResult.success(user);
    }


    /**
     * 查询用户详情
     *
     * @param dto
     * @return
     */
    @GetMapping("/team")
    public AjaxResult selectById(SysTeam dto) {
        log.info("Rest request to find user by id:{}", dto);
        SysUser user = userUtils.getCurrentUser();
        dto.setTeamCode(user.getTeamCode());
        List<SysTeam> result = teamService.selectByParams(dto);
        return AjaxResult.success(result);
    }

}
